/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufrgs.jsopa;

/**
 * The interrupt controller component has a private semaphore to maintain
 * interrupt requests coming from all other components. But I could not make the
 * operations on this semaphore automatic, since it cannot do a V operation
 * while locked in a synchronized method that called P. Other components have
 * then to call P() before calling set() and call V() before calling reset(). We
 * could also make IntController extends Semaphore instead of having one. Try
 * this out.
 */
class IntController {

    private Semaphore semhi;
    private int number;

    public IntController() {
        semhi = new Semaphore(1);
    }

    public void P() {
        semhi.P();
    }

    public void V() {
        semhi.V();
    }

    public synchronized void set(int n) {
        number = n;
    }

    public synchronized int get() {
        return number;
    }

    public synchronized void reset() {
        number = 0;
    }
}
